library("class")

getdata <- function(location) {
  tt <- read.table(location, header = T, sep = ";")
  return (tt)
}

getwd()

tt = read.table("D:\\Personal\\Desktop\\winequality-white.csv", header = T, sep = ";")

tt.nrm = ((tt - min(tt)) / (max(tt) - min(tt)))
tt.nrm
set.seed(1234)
idx <- sample(2, nrow(tt),replace = T, prob = c(0.80,0.20))

tt.nrm.trainSet <- tt.nrm[idx==1, 1:11]
tt.nrm.testSet <- tt.nrm[idx==2, 1:11]
tt.nrm.trainLabels <- tt[idx==1, 12]
tt.nrm.testLabels <- tt[idx==2, 12]

tt_pred <- knn(train = tt.nrm.trainSet, test = tt.nrm.testSet, cl = tt.nrm.trainLabels, k=9)
confusionTable <- print(table(tt_pred, tt.nrm.testLabels))
accuracy <- (sum(diag(confusionTable))/sum(confusionTable))
accuracy

tt_pred
names(tt_pred)
confusionTable
class(confusionTable)
